import java.util.Scanner;
public class Test2 {
    public static void main(String[] args) {
        //
        Main2 m = new Main2();
        m.main1();

    }

    public static int computeGcd(int number1, int number2) {
        while (number2 != 0) {
            int temp = number2;
            number2 = number1 % number2;
            number1 = temp;
        }
        return number1;
    }
}




// 注意类名必须为 Main, 不要有任何 package xxx 信息


class Main2 {




    public static void main1() {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();//组数
            for (int i = 0; i < n; i++) {
                //
                int x = in.nextInt();//数x
                int a = 0;//最公约数
                int b = 0;//逻辑或
                int c = 0;//抑或
                for(int j = 1;;j++){
                    if(x == j) continue;
                    a = func(x,j);
                    b = (x|j);
                    c = (x^j);
                    int num1 =(a+c-b);
                    int num2 =(a+b-c);
                    int num3 =(b+c-a);
                    if(num1>0 && num2>0 && num3>0){
                        System.out.println(j);
                    }
                    break;
                }
            }


        }
    }

    public static int func(int number1, int number2) {
        while (number2 != 0) {
            int temp = number2;
            number2 = number1 % number2;
            number1 = temp;
        }
        return number1;
    }
}
